package com.zk.mall.servlet;

import com.zk.mall.entity.Admin;
import com.zk.mall.service.AdminService;
import com.zk.mall.service.impl.AdminServiceImpl;
import com.zk.mall.util.MD5Util;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class addAdminServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=req.getParameter("adminname");
        String pwd=req.getParameter("adminpwd");
        pwd= MD5Util.md5(pwd);
        Admin admin=new Admin(name,pwd);
        AdminService adminService=new AdminServiceImpl();
        boolean flag=adminService.addAdmin(admin);
        if (flag){
            req.getRequestDispatcher("showAdmin.jsp").forward(req,resp);
        }else {}

    }
}
